package com.qf.ayc.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.ayc.foster.entity.Foster;
import com.qf.ayc.orders.entity.Orders;
import com.qf.ayc.product.entity.Product;
import com.qf.ayc.product.mapper.ProductMapper;
import com.qf.ayc.product.service.IProductService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.ayc.user.entity.Users;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaozhi
 * @since 2024-02-20
 */
@Service
@Slf4j
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements IProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public void add(Product product) {

        productMapper.insert(product);
    }

    @Override
    public void delete(Integer id) {
        productMapper.deleteById(id);
    }

    @Override
    public List<Product> List() {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        List<Product> orders = productMapper.selectList(queryWrapper);
        log.info("商品信息=",orders);
        return orders;
    }


    @Override
    public List<Product> getlist(Integer pageNum, Integer limit) {
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        Page<Product> page = new Page<>(pageNum, limit);
        productMapper.selectPage(page,wrapper);
        List<Product> records = page.getRecords();
        log.info("分页所有的商品信息为={}",records);
        return records;
    }

    @Override
    public List<Product> select(String type) {
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        wrapper.eq("type",type);
        List<Product> productCategory = productMapper.selectList(wrapper);
        return productCategory;
    }

//    @Override
//    public List<Product> searchlist(Product product) {
//        QueryWrapper<Product> wrapper = new QueryWrapper<>();
//        List<Product> products = productMapper.selectList(wrapper);
//        return products;
//    }

    @Override
    public List<Product> searchlist(Product product) {
        QueryWrapper<Product> wrapper = new QueryWrapper<>();
        wrapper.eq(product.getProname()!=null,"proname",product.getProname());

        return productMapper.selectList(wrapper);
    }




}
